package com.codeavatar.catools.helper;

import android.app.Activity;
import android.view.View;

import androidx.appcompat.widget.Toolbar;

import com.codeavatar.catools.R;

/**
 * +----------------------------------------------------------------------
 * | @Author: codeavatar   @Year：2022
 * +----------------------------------------------------------------------
 * | @Email: codeavatar@aliyun.com
 * +----------------------------------------------------------------------
 **/
public class CaToolbarHelper {

    private final String TAG = this.getClass().getSimpleName();

    //++++++++++++++++++++++++++++++++++++++
    //++ 外部方法
    //++++++++++++++++++++++++++++++++++++++

    public void toolbar(Toolbar toolbar, String title, int iconResId, View.OnClickListener clickListener){
        toolbar.setTitle(title);
        toolbar.setNavigationIcon(iconResId==0?R.mipmap.ca_bar_goback2:iconResId);
        toolbar.setNavigationOnClickListener(clickListener);
    }

    public void toolbar(Toolbar toolbar, Activity activity, String title){
        toolbar.setTitle(title);
        toolbar.setNavigationIcon(R.mipmap.ca_bar_goback2);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.finish();
            }
        });
    }

    private static CaToolbarHelper init;
    public static CaToolbarHelper init(){
        if(null == init){
            init = new CaToolbarHelper();
        }
        return init;
    }

    //++++++++++++++++++++++++++++++++++++++
    //++ 内部方法
    //++++++++++++++++++++++++++++++++++++++

    private CaToolbarHelper(){
        // Private constructor to prevent unwanted construction.
    }
}
